
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>多重入口 · test search plus plugin</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Lazy-loaded-entry-points.html" />
    
    
    <link rel="prev" href="Split-app-and-vendors.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="Introduction-to-Webpack.html">
            
                <a href="Introduction-to-Webpack.html">
            
                    
                    介绍 Webpack
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="Getting-started.html">
            
                <a href="Getting-started.html">
            
                    
                    第一步
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="Running-a-workflow.html">
            
                <a href="Running-a-workflow.html">
            
                    
                    开始工作流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="Automatic-browser-refresh.html">
            
                <a href="Automatic-browser-refresh.html">
            
                    
                    浏览器自动刷新
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="Requiring-files.html">
            
                <a href="Requiring-files.html">
            
                    
                    引入文件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="Introduction-to-React-JS.html">
            
                <a href="Introduction-to-React-JS.html">
            
                    
                    React JS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="Configuring-react-js.html">
            
                <a href="Configuring-react-js.html">
            
                    
                    配置 React JS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="Optimizing-rebundling.html">
            
                <a href="Optimizing-rebundling.html">
            
                    
                    优化重合并
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="Type-checking-with-flow.html">
            
                <a href="Type-checking-with-flow.html">
            
                    
                    Flow
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="CSS-Fonts-Images.md">
            
                <span>
            
                    
                    CSS, Fonts and Images
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="Loading-CSS.html">
            
                <a href="Loading-CSS.html">
            
                    
                    加载 CSS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="Automatic-CSS-refresh.html">
            
                <a href="Automatic-CSS-refresh.html">
            
                    
                    自动刷新 CSS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="Loading-LESS-or-SASS.html">
            
                <a href="Loading-LESS-or-SASS.html">
            
                    
                    加载 LESS 和 SASS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="Inlining-images.html">
            
                <a href="Inlining-images.html">
            
                    
                    内联 images
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="Inlining-fonts.html">
            
                <a href="Inlining-fonts.html">
            
                    
                    内联 fonts
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="Deployment-strategies.md">
            
                <span>
            
                    
                    部署策略
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="Structuring-configuration.html">
            
                <a href="Structuring-configuration.html">
            
                    
                    发布配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="Single-bundle.html">
            
                <a href="Single-bundle.html">
            
                    
                    合并成单文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="Split-app-and-vendors.html">
            
                <a href="Split-app-and-vendors.html">
            
                    
                    分离应用和第三方
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.4" data-path="Multiple-entry-points.html">
            
                <a href="Multiple-entry-points.html">
            
                    
                    多重入口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="Lazy-loaded-entry-points.html">
            
                <a href="Lazy-loaded-entry-points.html">
            
                    
                    懒加载入口文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="Isomorphic-app.html">
            
                <a href="Isomorphic-app.html">
            
                    
                    同构渲染
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="Wing-It-Like-a-Pro.html">
            
                <a href="Wing-It-Like-a-Pro.html">
            
                    
                    进阶
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="Optimizing-development.html">
            
                <a href="Optimizing-development.html">
            
                    
                    优化开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="Hot-loading-components.html">
            
                <a href="Hot-loading-components.html">
            
                    
                    热加载组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="JavaScript-next.html">
            
                <a href="JavaScript-next.html">
            
                    
                    使用下一代 JavaScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="Optimizing-caching.html">
            
                <a href="Optimizing-caching.html">
            
                    
                    优化缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="Matchers.html">
            
                <a href="Matchers.html">
            
                    
                    匹配器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="Lazy-loading-entry-points.md">
            
                <span>
            
                    
                    懒加载入口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="Creating-a-common-bundle.md">
            
                <span>
            
                    
                    创建一个复用代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="Understanding-chunks.html">
            
                <a href="Understanding-chunks.html">
            
                    
                    理解 Chunks
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="Authoring-libraries.html">
            
                <a href="Authoring-libraries.html">
            
                    
                    创建库
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >多重入口</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>Maybe you are building an application that has multiple urls. An example of this would be a solution where you have two, or more, different URLs responding with different pages. Maybe you have one user page and one admin page. They both share a lot of code, but you do not want to load all the admin stuff for normal users. That is a good scenario for using multiple entry points. A list of use cases could be:</p>
<p>&#x4F60;&#x7684;&#x5E94;&#x7528;&#x53EF;&#x80FD;&#x6709;&#x591A;&#x4E2A;&#x8DEF;&#x5F84;&#xFF0C; &#x5C31;&#x662F;&#x5E94;&#x7528;&#x4E2D;&#x6709;&#x4E24;&#x4E2A;&#x6216;&#x8005;&#x591A;&#x4E2A; URL &#x76F8;&#x5E94;&#x4E0D;&#x540C;&#x7684;&#x9875;&#x9762;&#xFF0C;&#x8FD9;&#x91CC;&#x5C31;&#x662F;&#x63D0;&#x4F9B;&#x8FD9;&#x6837;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x3002;&#x53EF;&#x80FD;&#x4F60;&#x6709;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x7528;&#x6237;&#x9875;&#x548C;&#x4E00;&#x4E2A;&#x7BA1;&#x7406;&#x5458;&#x9875;&#xFF0C;&#x4ED6;&#x4EEC;&#x5171;&#x4EAB;&#x4E86;&#x5F88;&#x591A;&#x4EE3;&#x7801;&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x60F3;&#x5728;&#x666E;&#x901A;&#x7528;&#x6237;&#x9875;&#x4E2D;&#x52A0;&#x8F7D;&#x6240;&#x6709;&#x7BA1;&#x7406;&#x5458;&#x9875;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x6240;&#x4EE5;&#x597D;&#x65B9;&#x6848;&#x662F;&#x4F7F;&#x7528;&#x591A;&#x91CD;&#x5165;&#x53E3;&#x3002;&#x4F7F;&#x7528;&#x7F18;&#x7531;&#x6709;&#x4E0B;&#x9762;&#x51E0;&#x6761;&#xFF1A;</p>
<ul>
<li>You have an application with multiple isolated user experiences, but they share a lot of code</li>
<li>You have a mobile version using less components</li>
<li>You have a typical user/admin application where you do not want to load all the admin code for a normal user</li>
</ul>
<ul>
<li>&#x4F60;&#x7684;&#x5E94;&#x7528;&#x6709;&#x591A;&#x79CD;&#x4E0D;&#x540C;&#x7684;&#x7528;&#x6237;&#x4F53;&#x9A8C;&#xFF0C;&#x4F46;&#x662F;&#x4ED6;&#x4EEC;&#x5171;&#x4EAB;&#x4E86;&#x5F88;&#x591A;&#x4EE3;&#x7801;&#x3002;</li>
<li>&#x4F60;&#x6709;&#x4E00;&#x4E2A;&#x4F7F;&#x7528;&#x66F4;&#x5C11;&#x7EC4;&#x4EF6;&#x7684;&#x624B;&#x673A;&#x7248;&#x672C;</li>
<li>&#x4F60;&#x7684;&#x5E94;&#x7528;&#x662F;&#x5178;&#x578B;&#x7684;&#x6743;&#x9650;&#x63A7;&#x5236;&#xFF0C;&#x4F60;&#x4E0D;&#x60F3;&#x4E3A;&#x666E;&#x901A;&#x7528;&#x6237;&#x52A0;&#x8F7D;&#x6240;&#x6709;&#x7BA1;&#x7406;&#x7528;&#x6237;&#x7684;&#x4EE3;&#x7801;&#x3002;</li>
</ul>
<p>Let us create an example with a mobile experience using less components:</p>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x4F7F;&#x7528;&#x66F4;&#x5C11;&#x7EC4;&#x4EF6;&#x7684;&#x624B;&#x673A;&#x9875;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#xFF1A;</p>
<p><em>webpack.production.config.js</em></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>);
<span class="hljs-keyword">var</span> webpack = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;webpack&apos;</span>);
<span class="hljs-keyword">var</span> node_modules_dir = path.resolve(__dirname, <span class="hljs-string">&apos;node_modules&apos;</span>);

<span class="hljs-keyword">var</span> config = {
  entry: {
    app: path.resolve(__dirname, <span class="hljs-string">&apos;app/main.js&apos;</span>),
    mobile: path.resolve(__dirname, <span class="hljs-string">&apos;app/mobile.js&apos;</span>),
    vendors: [<span class="hljs-string">&apos;react&apos;</span>] <span class="hljs-comment">// &#x5176;&#x4ED6;&#x5E93;</span>
  },
  output: {
    path: path.resolve(__dirname, <span class="hljs-string">&apos;dist&apos;</span>),
    filename: <span class="hljs-string">&apos;[name].js&apos;</span> <span class="hljs-comment">// &#x6CE8;&#x610F;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x4E86;&#x53D8;&#x91CF;</span>
  },
  <span class="hljs-built_in">module</span>: {
    loaders: [{
      test: <span class="hljs-regexp">/\.js$/</span>,
      exclude: [node_modules_dir],
      loader: <span class="hljs-string">&apos;babel&apos;</span>
    }]
  },
  plugins: [
    <span class="hljs-keyword">new</span> webpack.optimize.CommonsChunkPlugin(<span class="hljs-string">&apos;vendors&apos;</span>, <span class="hljs-string">&apos;vendors.js&apos;</span>)
  ]
};

<span class="hljs-built_in">module</span>.exports = config;
</code></pre>
<p>This configuration will create three files in the <code>dist/</code> folder. <strong>app.js</strong>, <strong>mobile.js</strong> and <strong>vendors.js</strong>. Most of the code in the <strong>mobile.js</strong> file also exists in <strong>app.js</strong>, but that is what we want. We will never load <strong>app.js</strong> and <strong>mobile.js</strong> on the same page.</p>
<p>&#x8FD9;&#x4E2A;&#x914D;&#x7F6E;&#x4F1A;&#x5728; <code>dist/</code> &#x6587;&#x4EF6;&#x5939;&#x4E0B;&#x521B;&#x5EFA;&#x4E09;&#x4E2A;&#x6587;&#x4EF6;&#xFF1A;<strong>app.js</strong>&#x3001;<strong>mobile.js</strong>&#x548C;<strong>vendors.js</strong>&#xFF0C;&#x5927;&#x90E8;&#x5206;&#x7684;&#x4EE3;&#x7801;&#x5728;<strong>mobile.js</strong>&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x4E5F;&#x6709;&#x4E00;&#x90E8;&#x5206;&#x5728; <strong>app.js</strong> &#x4E2D;&#xFF0C;&#x4E0D;&#x8FC7;&#x8FD9;&#x662F;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x7684;&#xFF0C;&#x6211;&#x4EEC;&#x4E0D;&#x4F1A;&#x5728;&#x540C;&#x4E00;&#x4E2A;&#x9875;&#x9762;&#x4E2D;&#x540C;&#x65F6;&#x52A0;&#x8F7D; <strong>app.js</strong> &#x548C; <strong>mobile.js</strong>&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Split-app-and-vendors.html" class="navigation navigation-prev " aria-label="Previous page: 分离应用和第三方">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Lazy-loaded-entry-points.html" class="navigation navigation-next " aria-label="Next page: 懒加载入口文件">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"多重入口","level":"1.5.4","depth":2,"next":{"title":"懒加载入口文件","level":"1.5.5","depth":2,"path":"Lazy-loaded-entry-points.md","ref":"Lazy-loaded-entry-points.md","articles":[]},"previous":{"title":"分离应用和第三方","level":"1.5.3","depth":2,"path":"Split-app-and-vendors.md","ref":"Split-app-and-vendors.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","search-pro","fontsettings","livereload"],"root":"./content","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"search-pro":{},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"version":"0.0.0"},"title":"test search plus plugin","gitbook":"*"},"file":{"path":"Multiple-entry-points.md","mtime":"2017-01-24T08:51:37.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-01-24T08:53:13.796Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    

    </body>
</html>

